import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;


public class test_find {
	public static void main(String[] args) {
		try {
			/* try connecting to the server */
			System.out.println("Registering Driver...");
			DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
			System.out.println("Driver Registered.");
			
			System.out.println("Attempting to connect...");
			Connection con = DriverManager.getConnection(
					"jdbc:oracle:thin:@localhost:1521:ug", "ora_i5l4", "a10653038");
			System.out.println("Connection Successful.");
			
			/* get input */
			System.out.print("Enter the string to find in ed_fname: ");
			Scanner sc = new Scanner(System.in);
			String input = new String(sc.next());
			
			/* execute sql code */
//			Statement stmt = con.createStatement();
			PreparedStatement ps = con.prepareStatement(
					"SELECT * " +
					"FROM editors e " +
					"WHERE lower(e.ed_fname) like ?");
//			ps.setString(1, "editors");
			ps.setString(1, "%" + input + "%");
//			System.out.println(ps.);
			ResultSet rs = ps.executeQuery();
			
			while(rs.next())
			{
				int rsize = rs.getFetchSize();
				String[] ed_data = new String[rsize];
//				System.out.print(rs.getFetchSize() + "    ");
				for (int i=1; i<=rsize; i++) {
					ed_data[i-1] = rs.getString(i);
				}			  
				
				for (int i=0; i<rsize; i++) {
					if (i != 9) 
						System.out.print(ed_data[i] + "\t");
					else System.out.println(ed_data[i]);
				}
			}
			
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Error: Connection Unsuccessful");
			e.printStackTrace();
		}
		System.out.println("Done");
		
	}
}
